<?php
// 首页控制器
class Controller_Admin_Message extends  Controller_Admin_Template 
{
    public function __construct($req, $res) 
    {
		$this->template = "smarty:admin/message/list";
		parent::__construct($req, $res);
	}

    public function action_index ($page = 1)
    {       
        $this->action_list($page);
    }

    public function action_list ($page = 1)
    {
        $limit    = Kohana::config('notice.notification.limit_per_page');
        $offset   = (max(1, (int) $page) - 1) * $limit;

        $message  = notice::factory('notification');
        $messages = $message->lists(user::current_user_id(), $offset, $limit);
        $count    = $message->count(user::current_user_id());

        $this->template->set('messages',   $messages);
        $this->template->set('pagination', $this->pagination($count, $limit));
    }

    public function action_content ($messageId)
    {
        $msgid = intval($messageId);
        $message = notice::factory('notification')->detail(user::current_user_id(), $msgid);
        notice::factory('notification')->set_read(user::current_user_id(), $msgid);

        $this->template->set_filename('smarty:admin/message/detail');
        $this->template->set('message', $message);
    }

    public function action_test()
    {
    }
}
